package com.jiesen.resource.modules.uploadFile.entity;

import lombok.Data;

@Data
public class Result<T> {
    public static int SUCCESS = 200;        //正确返回
    public static int ERROR = 502;          //错误返回
    private int code;
    private String msg = "成功";
    private int count =100;
    private Boolean success = true;
    private T data;

    public Result() {
    }

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(int code, T data) {
        this.code = code;
        this.data = data;
    }

    public static Result<Object> error(String msg) {
        return error(ERROR, msg);
    }

    public static Result<Object> error(int code, String msg) {
        Result<Object> r = new Result();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }

    public static Result<Object> error(int code, Object data) {
        Result<Object> r = new Result();
        r.setCode(code);
        r.setData(data);
        return r;
    }

    public static Result<Object> ok(String msg) {
        Result<Object> r = new Result();
        r.setCode(SUCCESS);
        r.setMsg(msg);
        return r;
    }

    public static Result<Object> ok(Object data) {
        Result<Object> r = new Result();
        r.setCode(SUCCESS);
        r.setData(data);
        return r;
    }

    public static Result<Object> ok(int code, Object data) {
        Result<Object> r = new Result();
        r.setCode(code);
        r.setData(data);
        return r;
    }

    public static Result<Object> ok(int code,int count,Object data) {
        Result<Object> r = new Result();
        r.setCode(code);
        r.setCount(count);
        r.setData(data);
        return r;
    }
}
